package cn.com.bsoft.wePortal.message.support

import ai.grakn.redismock.RedisServer
import cn.com.bsoft.kotlinEx.logger
import org.springframework.beans.factory.DisposableBean
import org.springframework.beans.factory.InitializingBean
import org.springframework.boot.context.properties.ConfigurationProperties


@ConfigurationProperties(prefix = "weportal.redis.mock")
class LocalMockRedisServerConf {
    var port: Int = 6379
}


class LocalMockRedisServer : InitializingBean, DisposableBean {

    lateinit var config: LocalMockRedisServerConf

    lateinit var server: RedisServer

    override fun afterPropertiesSet() {
        server = RedisServer.newRedisServer(config.port)
        server.start()
        logger.info("Start local redis at:${config.port}")
    }


    override fun destroy() {
        server.stop()
    }
}